package com.free.semantic.model.conceptmodel;

import com.free.semantic.req.RelaItemDef;
import com.free.semantic.req.RelationDefine;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class RelationDefineEntity {

    public RelationDefineEntity(Long semanticId, RelationDefine relationDefine) {
        this.semanticNetworkId = semanticId;
        this.name = relationDefine.getName();
        this.relationDefineItemEntities = new ArrayList<>();
        for (RelaItemDef relaItemDef : relationDefine.getRelaItemDefs()) {
            RelationDefineItemEntity relationDefineItemEntity = new RelationDefineItemEntity(relaItemDef);
            this.relationDefineItemEntities.add(relationDefineItemEntity);
        }
    }

    public RelationDefineEntity(RelationDefine relationDefine) {
        this.name = relationDefine.getName();
        this.relationDefineItemEntities = new ArrayList<>();
        for (RelaItemDef relaItemDef : relationDefine.getRelaItemDefs()) {
            RelationDefineItemEntity relationDefineItemEntity = new RelationDefineItemEntity(relaItemDef);
            this.relationDefineItemEntities.add(relationDefineItemEntity);
        }
    }

    public RelationDefineEntity() {

    }

    public RelationDefine toRelationDefine() {
        RelationDefine relationDefine = new RelationDefine();
        relationDefine.setName(this.name);
        List<RelaItemDef> relaItemDefs = new ArrayList<>();
        for (RelationDefineItemEntity relationDefineItemEntity : relationDefineItemEntities) {
            relaItemDefs.add(relationDefineItemEntity.toRelaItemDef());
        }
        relationDefine.setRelaItemDefs(relaItemDefs);
        return relationDefine;
    }

    private Long id;

    private String name;

    private Long semanticNetworkId;

    private List<String> parameterList; // 事物参数列表

    private List<RelationDefineItemEntity> relationDefineItemEntities;

}